%Let us generate nex=50 vector-valued sequences of length T=50; each vector has size O=2.
O = 3;
T = 240;
nex = 1;
data=zeros(3,240,1);
data(:,:,1)=Gel4(:,[1 2 4])';

%data = randn(O,T,nex);
%Now let use fit a mixture of M=2 Gaussians for each of the Q=2 states using K-means.
M = 2;
Q = 3;
left_right = 0;

prior0 = [1;0;0];
prior0 = prior0/sum(prior0);
transmat0 = [79/80 1/80 0; 0 79/80 1/80; 0 0 1];
reshape(data, [O T*nex]);
%pause
[mu0, Sigma0] = mixgauss_init(Q*M, reshape(data, [O T*nex]), 'full');
%pause
mu0 = reshape(mu0, [O Q M]);
Sigma0 = reshape(Sigma0, [O O Q M]);
mixmat0 = mk_stochastic(rand(Q,M));
%pause

%Finally, let us improve these parameter estimates using EM.
[LL, prior1, transmat1, mu1, Sigma1, mixmat1] = ...
    mhmm_em(data, prior0, transmat0, mu0, Sigma0, mixmat0, 'max_iter', 100);

obsmat=[1:3];

B = mixgauss_prob(data(:,:,1),mu1, Sigma1, mixmat1);
[path] = viterbi_path(prior1, transmat1, B);   